<?php
namespace Es\Exceptions;

class CommonExceptions extends \Exception
{
    //error_code
    const CODE_NOT_FOUND_ERROR = 400000;

    //operate error
    const ERROR_OPERATE        = 500000;

    const DOCU_ID_NOT_EMPTY    = 600003;
    const DOCU_BODY_NOT_EMPTY  = 600004;
    const BLUK_NUM_ERROR       = 610001;

    const FILEDS_NUM_NOT_FOUNT = 620001;

    //error message
    const DOCU_ID_NOT_EMPTY_MSG    = "文档ID不能为空";
    const DOCU_BODY_NOT_EMPTY_MSG  = "文档内容不能为空";
    const CODE_NOT_FOUND_ERROR_MSG = "错误码未找到";
    const BLUK_NUM_ERROR_MSG       = "批量处理的数据量应该在2-1000之间";
    const FILEDS_NUM_NOT_FOUNT_MSG = "类型不存在";


    const CODE_MSG_LIST = [
        self::DOCU_ID_NOT_EMPTY    => self::DOCU_ID_NOT_EMPTY_MSG,
        self::DOCU_BODY_NOT_EMPTY  => self::DOCU_BODY_NOT_EMPTY_MSG,
        self::CODE_NOT_FOUND_ERROR => self::CODE_NOT_FOUND_ERROR_MSG,
        self::BLUK_NUM_ERROR       => self::BLUK_NUM_ERROR_MSG
    ];

    public function __construct(int $code, $message = '')
    {
        if(empty($message)){
            if(!isset(self::CODE_MSG_LIST[$code])){
                throw new CommonExceptions(self::CODE_NOT_FOUND_ERROR);
            }
            $message = self::CODE_MSG_LIST[$code];
        }
        parent::__construct($message, $code);
    }
}

